<?php
session_start();
if(!@$_SESSION['username']) {
  echo "<script>window.location.href='login.php';</script>";
}
?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<?php
		include_once('../../libraries/esaydb.class.php');
		if($_GET) {
            $db = new EasyDB();

            $exist_sql = "SELECT ispay FROM ob_order WHERE rid = ?";
            $result_exist = $db->queryOne($exist_sql, array($_GET['rid']));
            if($result_exist['ispay'] == 'yes') {
                echo "<script>alert('已经付款，无需重复');history.go(-1);</script>";
                exit(1);
            }

			$bool = $db->update("ob_order",array('ispay'=>'yes'),array('rid'=>$_GET['rid']));
            if($bool) {

                //票数减一
                $sid = $_GET['sid'];
                $type = $_GET['site_type'];

                if($type == 'have') {
                    $sql_s = "SELECT number FROM ob_station WHERE id = ?";
                    $result_s = $db->queryOne($sql_s, array($_GET['sid']));
                    $result_s['number']--;
                    $db->update("ob_station",array('number'=>$result_s['number']),array('id'=>$_GET['sid']));
                }else if($type == 'none') {
                    $sql_s = "SELECT num_none FROM ob_station WHERE id = ?";
                    $result_s = $db->queryOne($sql_s, array($_GET['sid']));
                    $result_s['num_none']--;
                    $db->update("ob_station",array('num_none'=>$result_s['num_none']),array('id'=>$_GET['sid']));
                }else{
                    echo "<script>alert('付款失败');history.go(-1);</script>";
                }

				echo "<script>alert('付款成功');window.location.href='../../order-list.php';</script>";
			}else{
				echo "<script>alert('付款失败');history.go(-1);</script>";
			}
		}else{
			echo "<script>alert('参数错误');history.go(-1);window.close();';</script>";
		}
	?>
</body>
</html>
